package day02_oop_code.com.itheima.d10_interface_demo;

import java.util.ArrayList;

public class ClassDataImpl2 implements ClassData{

    private ArrayList<Student> students;
    public ClassDataImpl2(ArrayList<Student> students) {
        this.students = students;
    }

    public ClassDataImpl2() {
    }

    @Override
    public void printAllStudentInfo() {
        System.out.println("ClassDataImpl2.printAllStudentInfo");
        //打印班级全部学生信息，含男生人数，女生人数。
        int count = 0;
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            System.out.println("s.toString() = " + s.toString());
            if (s.getSex() == '男'){
                count++;
            }

        }
        //男生人数
        System.out.println("男生人数 = " + count);
        //女生人数
        System.out.println("女生人数 = " + (students.size() - count));
    }

    @Override
    public void printAllStudentAverageScore() {
        //打印班级全部学生的平均分，要求去掉最高分，最低分
        System.out.println("ClassDataImpl2.printAllStudentAverageScore");
        Student s1 = students.get(0);
        double score = s1.getScore();
        double allScore = score;
        double max = score;
        double min = score;

        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            double sc = student.getScore();
            allScore += sc;
            if (sc > max){
                max = sc;
            }
            if (sc < min){
                min = sc;
            }
        }
        //最高分
        System.out.println("最高分 = " + max);
        //最低分
        System.out.println("最低分 = " + min);
        //平均分
        System.out.println("平均分 = " + (allScore - max - min) / (students.size() - 2));

    }
}
